<? 
	$title="Successful Purchase";
	require("required/dbconnect.php");
	require("required/share_function.php");
	$_SESSION['pid']=-1;
	require("required/header.php");
	require("required/function.php"); 
	
	$bid=$_GET['id'];
	
	$get_bill=mysql_query("select * from os_bill_details where id=$bid");
	
	
	$b=mysql_fetch_array($get_bill,MYSQL_ASSOC);
	
	if($b['uid']!=$member_id)
	{
		errRedirect(2,"Invalid Access!",$_SERVER['PHP_SELF'],0);	
	}
	
	$get_item=mysql_query("select * from os_bill_items where bid=$bid")or die("line 11".mysql_error());
	
	$orange=$b['survey_1']*10;
	$gray=50-($b['survey_1']*10);
?>
		
				<table width="100%" cellpadding="6" cellspacing="0">
					<td align="left" class="page_title_bar" width="100%">
					Successful purchase 
					</td>
					<tr>
					
						<Td valign="top" height="400">
							<table width="100%">
							
							
							<tr>
								<td>
								<table width="100%" cellpadding="0" cellspacing="0">
								<td width="33%">Received Date</td><td width="60%">: <font color="#0066CC"><?= $b['goods_received_date'] ?></font></td>
								<td width="7%" rowspan="3" align="right">
								</td>
								
								<tr>
								<td>Your rate for this purchase</td><td>: <img src="images/1x1_orange.gif" width="<?= $orange ?>" height="5" align="middle"><img src="images/1x1_gray.gif" width="<?= $gray ?>" height="5" align="middle"> <?= scoreBar($b['survey_1']) ?></td>
								</tr>
								<tr>
								<td>Your comment for this purchase</td><td>: <?= $b['review'] ?></td>
								</tr>
								</table>
								<table width="90%" bgcolor="#CCCCCC" cellpadding="1" cellspacing="1">
								<tr class="table_header" align="center">
									<td width="42%">Product</td><td width="13%">Unit Price(RM)</td><td width="15%">Product code</td><td width="11%">Quantity</td>
                                    <td width="15%">Total(RM)</td>
								</tr>
							<?
									$total_item=0;
									$total_piece=0;
									$total_allprice=0;
									$no=1;
									while($c=mysql_fetch_array($get_item))
									{
										$total_price=0;
										$get_product=mysql_query("select a.product_name_eng,a.product_code,b.description,b.unit_price from os_products a inner 
										join os_product_inventory b on a.id=b.pid where b.id=".$c['item_id']);
										$a=mysql_fetch_array($get_product,MYSQL_ASSOC);
										$total_price=$a['unit_price']*$c['quantity'];
										$total_allprice=$total_allprice+$total_price;
										
										if($no%2==0)
										{
											$class1="table_item_even";
											$class2="table_item_odd";
										}
										else
										{
											$class1="table_item_odd";
											$class2="table_item_even";
										}					
										
																				
							?>
								 <tr height="30" valign="top" class="<?= $class1 ?>"  onmouseover="this.className='table_item_mouseover'" onmouseout="this.className='<?= $class1 ?>'" align="center">
									<td align="left"><a href="product_viewfull.php?id=<?= $c['pid'] ?>"><?= $a['product_name_eng'] ?></a>
									<br>Product Option : <strong><?= $a['description'] ?></strong></td><td><?= $a['unit_price'] ?></td>
                                    <td><?= $a['product_code'] ?></td><td><?= $c['quantity'] ?></td>
									<td align="right"><?= number_format($total_price,2) ?></td>
								</tr>
							<? 
								} 
							?>
							</table></td>
							</tr>
							
							<tr>
								<td><strong>Order Information</strong></td>
							</tr>
							<tr>
								<td>
								<table width="100%">
								<tr>
								<td width="13%">Order number</td><td width="1%">:</td><td width="29%"><?= $b['invoice_number'] ?>	</td>
								<td width="16%">Order amount</td><td width="1%">:</td><td width="40%"><?= number_format($b['total_amount'],2) ?></td>
								</tr>
								<tr>
								<td width="13%">Order date</td><td width="1%">:</td><td width="29%"><?= $b['create_date'] ?></td>
								<td width="16%">Shipment fees</td><td width="1%">:</td><td width="40%"><?= number_format($b['transport_fees'],2) ?></td>
								</tr>
								<tr>
								<td width="13%"></td><td width="1%"></td><td width="29%"></td>
								<td width="16%">Discount</td><td width="1%">:</td><td width="40%">-<?= $b['discount'] ?>%</td>
								</tr>
								 <?
									$total_amount=$b['transport_fees']+$b['total_amount']; 
									$discount=($b['discount']/100)*$total_amount;
									$final_amount=$total_amount-$discount;
								?>
                                
                                 <?
					
										$get_voucher=mysql_query("select * from os_discount_voucher_used where bill_id=$bid")or die(mysql_error());
										if(mysql_num_rows($get_voucher)>0)
										{
											
											$voucher=mysql_query("select * from os_discount_voucher where id='".mysql_result($get_voucher,0,"voucher_id")."'")or die(mysql_error());
						
											$v=mysql_fetch_array($voucher,MYSQL_ASSOC);
											
											if($v['discount_type']=="P")
											{
												$desc=number_format($v['discount_amount'],0)."% off";
												$discount=($total_allprice*$v['discount_amount'])/100;
												
												$final_amount=$final_amount-$discount;
											}
											else
											{
												$desc=" RM".$v['discount_amount']." off";
												$discount=$v['discount_amount'];
												$final_amount=$final_amount-$v['discount_amount'];
											}
											
											
									?>
								   <tr>
										<td width="20%"></td><td width="2%"></td><td width="27%"></td>
										<td><?= $v['voucher_name'] ?>(<?= $v['voucher_code'] ?>) <?= $desc ?> </td><td width="1%">:</td><td> - <?= number_format($discount,2) ?></td>
									
								
									<?		
											
										}
									?>	
								<tr>
								<td width="13%"></td><td width="1%"></td><td width="29%"></td>
								<td width="16%">Overall amount</td><td width="1%">:</td><td width="40%"><?= number_format($final_amount,2) ?></td>
								</tr>
								</table>
								</td>
							</tr>
							<tr>
								<td><strong>Receiver Information</strong></td>
							</tr>
							<tr>
								<td>
								<table width="100%">
								<tr>
								<td width="13%">Name</td><td width="1%">:</td><td width="29%"><?= $b['receiver_name'] ?>
								</td>
								<td width="16%">Email</td><td width="1%">:</td><td width="40%"><?= $b['email'] ?>
								</td>
								</tr>
								<tr>
								<td width="13%">Address</td><td width="1%">:</td><td width="29%"><?= $b['address1'] ?>
								</td>
								<td width="16%">Contact number</td><td width="1%">:</td><td width="40%"><?= $b['contact_number'] ?>
								</td>
								<tr>
								<td colspan="2"></td><td width="29%"><?= $b['address2'] ?>
								</td>
								</tr>
								<tr>
								<td width="13%">Postcode</td><td width="1%">:</td><td width="29%"><?= $b['postcode'] ?>
								</td>
								<td width="16%">City</td><td width="1%">:</td><td width="40%"><?= $b['city'] ?>
								</td>
								</tr>
								
								<?
									if($b['state']!=0)
									{
										$get_place=mysql_query("select * from os_state where id=".$b['state'])or die(mysql_error());
										$place=mysql_result($get_place,0,"name_eng");
										$state="$place";
									}
									else
									{
										$state="-";
									}
									
									if($b['country']!=0)
									{
									
										$get_country=mysql_query("select * from os_country where id=".$b['country'])or die(mysql_error());
										$country=mysql_result($get_country,0,"engname");
										$word_country="$country";
									}
									else
									{
										$word_country="Other";
									} 
									
							?>
							<tr>
								<td>State</td><td>:</td><td><?= $state ?></td>
								<td>Country</td><td>:</td><td>
								<?= $word_country ?>
								</td>
							</tr>
							<tr>
								<td>Remark</td><td>:</td><td colspan="4"><?= $b['message'] ?></td>
								
							</tr>
							
								</table>
								</td>
							</tr>
							</form>
							
							</table>
							
						</Td>
					</tr>
					<?
								$get_payment=mysql_query("select * from os_payment_record where bid=$bid and uid=$member_id order by create_datetime asc");
								if(mysql_num_rows($get_payment)>0)
								{
							?>
								<tr>
								<td>
								<table width="100%" cellpadding="0" cellspacing="0" class="solidborder">
								<?
									$no=1;
									while($p=mysql_fetch_array($get_payment))
									{
								?>
								<tr>
									<td width="100%">
										<table width="100%">
											<td width="13%" colspan="6" class="table_header"><b>Payment record <?= $no ?></b></td>
											<tr>
												<td>Payment date</td><td width="1%">:</td><td width="29%"><?= $p['paymentdate'] ?></td>
												<td width="16%">Paid amount</td><td width="1%">:</td><td width="40%">RM <?= number_format($p['paidamount'],2) ?></td>
											</tr>
											<tr>
												<td>Bank</td><td>:</td><td><?= $p['paymentbank'] ?></td>
												<td>Account number</td><td>:</td><td><?= $p['accountnumber'] ?></td>
											</tr>
											<tr>
												<td >Remark</td><td>:</td ><td colspan="4"><?= $p['message'] ?></td>
											</tr>
											<tr>
												
											</tr>
										</table>
									
									</td>
									
								</tr>
								<?
									$no++; } ?>
								</table>
								</td>
							</tr>
							
							<? } ?>		  
			  	</table>
			
<? require("required/footer.php"); ?>	